//
//  UserInfoManage.m
//  jianzhi
//
//  Created by 零零壹 on 16/3/25.
//  Copyright © 2016年 零零壹. All rights reserved.
//

#import "UserInfoManage.h"
#import "JPUSHService.h"

@interface UserInfoManage ()
{
    NSArray *_dataArray;
}
@end

@implementation UserInfoManage

+(instancetype)sharedInstance
{
    static dispatch_once_t predicate;
    
    static UserInfoManage *userInfoManage;
    
    dispatch_once(&predicate, ^{
        userInfoManage=[[UserInfoManage alloc] init];
    });
    return userInfoManage;
}

-(void)setUserInfo:(UserInfo *)userInfo
{
    _userInfo=userInfo;
    
    if (userInfo)
    {
        NSString *userId = userInfo.uid;
        NSString *token=userInfo.access_token;
        NSString *type = userInfo.type;
        NSString *name = userInfo.realname;
        NSString *headUrl = userInfo.headimgurl;
        NSString *tid = userInfo.teacher_id;
        NSString *student_title = userInfo.student_title;
        NSString *teacher_title = userInfo.teacher_title;
        
        NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
        [userDefaults setObject:userId forKey:kUserId];
        [userDefaults setObject:token forKey:kAccessToken];
        [userDefaults setObject:type forKey:Ktype];
        [userDefaults setObject:name forKey:@"Name"];
        [userDefaults setObject:headUrl forKey:@"Head"];
        [userDefaults setObject:tid forKey:@"tid"];
        [userDefaults setObject:student_title forKey:@"student_title"];
        [userDefaults setObject:teacher_title forKey:@"teacher_title"];
    }else
    {
        NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
        [userDefaults setObject:nil forKey:kUserId];
        [userDefaults setObject:nil forKey:kAccessToken];
        [userDefaults setObject:nil forKey:Ktype];
        [userDefaults setObject:nil forKey:@"Name"];
         [userDefaults setObject:nil forKey:@"Head"];
        [userDefaults setObject:nil forKey:@"student_title"];
        [userDefaults setObject:nil forKey:@"tid"];
        
//        [JPUSHService setTags:nil alias:@"ABCDEDG" callbackSelector:nil target:nil];
    }
}


//-(void)doConnectIM:(NSString *)token
//{
//    [[RCIM sharedRCIM]connectWithToken:token success:^(NSString *userId)
//    {
//        NSLog(@"connectWithToken success");
//    } error:^(RCConnectErrorCode status)
//    {
//        NSLog(@"connectWithToken RCConnectErrorCode");
//    } tokenIncorrect:^
//    {
//        NSLog(@"connectWithToken tokenIncorrect");
//    }];
//}


+(BOOL)isLogined
{
    UserInfoManage *manage=[UserInfoManage sharedInstance];
    if (manage.userInfo)
    {
        return true;
    }
    return false;
}

+(void)logout
{
    UserInfoManage *manage=[UserInfoManage sharedInstance];
    manage.userInfo=nil;
    [JPUSHService setTags:nil alias:@"" callbackSelector:nil target:nil];
//    [[RCIM sharedRCIM]logout];
}


@end

@implementation UserInfo

@end
